package com.yootk.jdbc.service;

import com.yootk.jdbc.vo.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class BookServiceImpl implements IBookService{
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Override
    public boolean add(Book book) {
        String sql = "INSERT INTO book(title,author,price) VALUES(?,?,?)" ;
        return this.jdbcTemplate.update(sql,book.getTitle(),book.getAuthor(),book.getPrice()) > 0;
    }

    @Override
    public boolean edit(Book book) {
        String sql = "UPDATE book SET title=?,author=?,price=? WHERE bid=?" ;
        return this.jdbcTemplate.update(sql,book.getTitle(),book.getAuthor(),book.getPrice(),book.getBid()) > 0;
    }
}
